<template>
    <bi-form ref="form">
        <bi-form-item label="等级名称" >
            <bi-input v-model="form.title" required ></bi-input>
        </bi-form-item>
        <bi-form-item label="类型" v-if="add" >
            <bi-radio v-model="form.type" :option="typeOption"></bi-radio>
        </bi-form-item>
        <bi-form-item label="升级金额" v-if="form.type=='consume'" >
            <bi-input v-model="form.amount" required type="number" :rule="{min:1}" ruleMessage="升级金额不能小于1元" >
                <template #after>元</template>
            </bi-input>
        </bi-form-item>
        <bi-form-item label="简介" >
            <bi-textarea v-model="form.brief"></bi-textarea>
        </bi-form-item>
    </bi-form>
</template>


<script>
export default{
    dialog:{
        
    },
    data(){

        let typeOption = [
            { value:'consume',label:'消费等级' },
            { value:'special',label:'特殊等级' }
        ]

        let form = {
            level_id:'',
            title:'',
            type:'consume',
            amount:0,
            brief:''
        }

        this.$assign(form,this.item);
        
        let add = this.item==undefined?true:false;


        return {
            form,
            add,
            typeOption
        }
    },
    props:{
        item:Object
    },
    methods:{
        dialogOk(){
            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({app:'shop',controller:'admin.MemberLevel',action:'save'}),
                    data:this.form,
                    success:(data)=>{
                        this.$toast('保存成功');
                        this.dialog.callback(this.form.type);
                        this.dialog.close();
                    }
                })
            }

            return false;
        }
    }
}
</script>
